package com.atguigu.principle.singleresponsibility.singleton.type3;

/**
 * @Author: yangtao
 * @Description:
 */
public class Singleton4 {

    public static void main(String[] args) {
   Singleton instance = Singleton.getInstance();
   Singleton instance2 = Singleton.getInstance();
        System.out.println(instance == instance2);
    }
}

class Singleton{
   private static Singleton instance;

   private Singleton(){

   }

   //提供一个静态公有方法 使用到方法 采取创建，同步代码块
    public static synchronized Singleton getInstance(){
       if(instance == null){
            instance = new Singleton();
       }
       return instance;
    }


}
